package com.ruoyi.service.basic.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.domain.basic.MesSupplier;
import com.ruoyi.mapper.basic.MesSupplierMapper;
import com.ruoyi.service.basic.IMesSupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 供应商信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-01-01
 */
@Service
public class MesSupplierServiceImpl implements IMesSupplierService 
{
    @Autowired
    private MesSupplierMapper mesSupplierMapper;

    /**
     * 查询供应商信息
     * 
     * @param supplierId 供应商信息主键
     * @return 供应商信息
     */
    @Override
    public MesSupplier selectMesSupplierBySupplierId(Long supplierId)
    {
        return mesSupplierMapper.selectMesSupplierBySupplierId(supplierId);
    }

    /**
     * 查询供应商信息列表
     * 
     * @param mesSupplier 供应商信息
     * @return 供应商信息
     */
    @Override
    public List<MesSupplier> selectMesSupplierList(MesSupplier mesSupplier)
    {
        return mesSupplierMapper.selectMesSupplierList(mesSupplier);
    }

    /**
     * 新增供应商信息
     * 
     * @param mesSupplier 供应商信息
     * @return 结果
     */
    @Override
    public int insertMesSupplier(MesSupplier mesSupplier)
    {
        mesSupplier.setCreateTime(DateUtils.getNowDate());
        return mesSupplierMapper.insertMesSupplier(mesSupplier);
    }

    /**
     * 修改供应商信息
     * 
     * @param mesSupplier 供应商信息
     * @return 结果
     */
    @Override
    public int updateMesSupplier(MesSupplier mesSupplier)
    {
        mesSupplier.setUpdateTime(DateUtils.getNowDate());
        return mesSupplierMapper.updateMesSupplier(mesSupplier);
    }

    /**
     * 批量删除供应商信息
     * 
     * @param supplierIds 需要删除的供应商信息主键
     * @return 结果
     */
    @Override
    public int deleteMesSupplierBySupplierIds(Long[] supplierIds)
    {
        return mesSupplierMapper.deleteMesSupplierBySupplierIds(supplierIds);
    }

    /**
     * 删除供应商信息
     * 
     * @param supplierId 供应商信息主键
     * @return 结果
     */
    @Override
    public int deleteMesSupplierBySupplierId(Long supplierId)
    {
        return mesSupplierMapper.deleteMesSupplierBySupplierId(supplierId);
    }

    /**
     * 校验供应商编码是否唯一
     * 
     * @param mesSupplier 供应商信息
     * @return 结果
     */
    @Override
    public String checkSupplierCodeUnique(MesSupplier mesSupplier)
    {
        Long supplierId = StringUtils.isNull(mesSupplier.getSupplierId()) ? -1L : mesSupplier.getSupplierId();
        MesSupplier info = mesSupplierMapper.checkSupplierCodeUnique(mesSupplier.getSupplierCode());
        if (StringUtils.isNotNull(info) && info.getSupplierId().longValue() != supplierId.longValue())
        {
            return "1"; // 不唯一
        }
        return "0"; // 唯一
    }

    /**
     * 查询启用状态的供应商列表
     * 
     * @return 供应商列表
     */
    @Override
    public List<MesSupplier> selectActiveSupplierList()
    {
        return mesSupplierMapper.selectActiveSupplierList();
    }

    /**
     * 根据供应商类型查询供应商
     * 
     * @param supplierType 供应商类型
     * @return 供应商列表
     */
    @Override
    public List<MesSupplier> selectMesSupplierByType(String supplierType)
    {
        return mesSupplierMapper.selectMesSupplierByType(supplierType);
    }
}